package nancal.mp.db.mongo.entity

import nancal.mp.db.mongo.*
import nbcp.base.db.IdCodeName
import nbcp.base.db.IdName
import nbcp.base.db.IdUrl
import nbcp.base.db.annotation.Cn
import nbcp.base.db.annotation.DbEntityGroup
import nbcp.base.db.annotation.DbEntityIndex
import nbcp.base.db.annotation.DbEntityIndexes
import nbcp.base.model.BaseMarkEntity
import nbcp.myoql.db.CityCodeName
import nbcp.myoql.db.comm.RemoveToSysDustbin
import nbcp.myoql.db.mongo.entity.BasicUser
import nbcp.myoql.db.mongo.entity.BasicUserLoginInfo
import nbcp.myoql.db.mongo.entity.SysOrganization
import nbcp.myoql.weixin.WxUserData
import org.springframework.data.mongodb.core.mapping.Document
import java.io.Serializable
import java.time.LocalDate
import java.time.LocalDateTime

//企业用户
@Document
@DbEntityGroup("corp")
@RemoveToSysDustbin
@DbEntityIndexes(
    DbEntityIndex("loginName", unique = true)
)
open class CorpUser(
    var address: String = "",

    @Cn("mysql系统保存的Id")
    var mysqlId: Long = 0,

    var wxUserInfo: WxUserData = WxUserData(),

    var corp: IdName = IdName(),
    var dept: IdName = IdName(),      //部门
    var depts: MutableList<nancal.mp.db.mongo.entity.DeptDefine> = mutableListOf(),   //多部门使用  目前单部门
    var roles: MutableList<IdName> = mutableListOf(),     //sass角色

    var devroles: MutableList<IdName> = mutableListOf(),   //dev系统内角色
    var dev2roles: MutableList<IdName> = mutableListOf(),  //dev v2 角色保存位置

    //是否是公司管理员
    var isAdmin: Boolean = false,
    var status: Boolean = false,   // 是否冻结账户
//        var wxUserInfoRef: WxUserInfoModel = WxUserInfoModel(),
    //相互隔离系统中的app用户
    var appUser: IdName = IdName(),
    var app: String = ""

) :  BasicUser(), Serializable


@Document
@DbEntityGroup("corp")
@DbEntityIndexes(
    DbEntityIndex("loginName", unique = true),
)
data class CorpLoginUser(
    var errorLoginTimes: Byte = 0,
    var forget_password: Boolean = false
) :  BasicUserLoginInfo(), Serializable

/**
 * 企业信息
 */
@Document
@DbEntityGroup("corp")
@RemoveToSysDustbin
open class Corporation(
    var remark: String = "",    //简介
    var buildAt: LocalDateTime? = null,     //成立日期

    //规模
    var personCount: PersonCountEnum? = null,
    //联系人
    var concatName: String = "",
    //联系电话
    var phone: String = "",
    //email
    var email: String = "",

    var keywords: String = "",
    var banner: IdUrl = IdUrl(),
//        var siteMenus: MutableList<SiteMenuItem> = mutableListOf(),
//        var sysMenus: MutableList<SysMenuItem> = mutableListOf(),
    var corpWxSetting: nancal.mp.db.mongo.entity.CorpWxSetting = nancal.mp.db.mongo.entity.CorpWxSetting(),     //企业微信设置

    var address: String = "",           //企业地址

    var weixin: String = "",            //微信公众号
    var industry: IndustryEnum? = null,    //行业
    var qualifications: MutableList<IdUrl> = mutableListOf(), //资质照片
    var images: MutableList<IdUrl> = mutableListOf(),   //形象照片

    //首页配置项
    var h1: String = "",
    var h2: String = "",
    var h3: String = "",
    var headerImg: String = ""
) :  SysOrganization(), Serializable


/**
 * Saas平台的菜单集合
 */
@Document
@DbEntityGroup("corp")
@RemoveToSysDustbin
class SaasMenusDevops() : nancal.mp.db.mongo.entity.SaasMenuItem()
class SaasMenusMake() : nancal.mp.db.mongo.entity.SaasMenuItem()
class SaasMenusDevelopment() : nancal.mp.db.mongo.entity.SaasMenuItem()
class SaasMenusData() : nancal.mp.db.mongo.entity.SaasMenuItem()
class SaasMenusManagement() : nancal.mp.db.mongo.entity.SaasMenuItem()

//
//{
//        var devops = mutableListOf<SaasMenuItem>()
//        var make = mutableListOf<SaasMenuItem>()
//        var dev = mutableListOf<SaasMenuItem>()
//        var data = mutableListOf<SaasMenuItem>()
//        var management = mutableListOf<SaasMenuItem>()
//}


/**
 * 公司部门 信息
 *
 */
@Cn("公司部门")
@Document
@DbEntityGroup("corp")
data class DepartmentInfo(

    @Cn("所属公司")
    var corp: IdName = IdName(),

    @Cn("部门名称")
    var name: String = "",

    @Cn("上级部门")
    var parent: IdName = IdName(),

    ) : BaseMarkEntity()


//返回的tree结构
data class TreeData(
    var id: String = "",
    var name: String = "",
    var parent: IdName = IdName(),
    var children: List<nancal.mp.db.mongo.entity.TreeData>? = null
)


/**
 * 企业注册申请
 */
@Document
@DbEntityGroup("corp")
open class CorpRegisteRequest : nancal.mp.db.mongo.entity.Corporation() {
    var status: ApproveStatusEnum = ApproveStatusEnum.Create
    var approveMessage: String = ""
}

/**
 * 电子签章
 */
@Document
@DbEntityGroup("corp")
data class DigitSignInfo(
    var corp: IdName = IdName(),
    var key: String = "",
    var secret: String = ""
) : BaseMarkEntity()


/**
 * 商户注销申请
 */
@Document
@DbEntityGroup("corp")
data class CorpDestroyRequest(
    var reason: String = "",
    var remark: String = "",
    var validateCode: String = ""
) :  SysOrganization(), Serializable


/**
 * 企业自定义内部分类.
 * sysCategoryPath 表示 系统分类
 * corpCategoryPath 表示 企业自定义分类
 */
@Document
@DbEntityGroup("corp")
data class CorpCategory(
    var code: String = "", //树型结构。类似城市代码。
    var name: String = "",
    var english: String = "", //英文
    var parentPath: MutableList<IdCodeName> = mutableListOf(),
    var logo: IdUrl = IdUrl(),   //logo
    var order: Float = 0.0F,    //排序
    var corpId: String = "",    //企业Id
    var sysCategoryPath: MutableList<IdCodeName> = mutableListOf(), //表示分类的路径
    var banner: IdUrl = IdUrl() //淘对Banner
) : BaseMarkEntity()


/**
 * 企业交费记录
 */
@Document
@DbEntityGroup("corp")
data class CorpFeeLog(
    var code: String = "",  //订单号
    var type: String = "",  //订单类型
    var amount: Int = 0,    //金额
    var remark: String = ""
) : BaseMarkEntity()


/**
 * 仓库信息
 */
@Document
@DbEntityGroup("corp")
data class WarehouseInfo(
    var name: String = "",
    var city: CityCodeName = CityCodeName(),
    var address: String = "",
    var remark: String = "",
    var createBy: IdName = IdName(),
    var corp: IdName = IdName()
) : BaseMarkEntity()


//物流公司
@Document
@DbEntityGroup("corp")
data class LogisticsInfo(
    var name: String = "",      //快递公司
    var type: LogisticsTypeEnum = LogisticsTypeEnum.Road,
    var remark: String = ""     //快递备注
) : BaseMarkEntity()


@Cn("用户反馈信息")
@Document
@DbEntityGroup("corp")
data class FeedBackInfo(

    @Cn("所属系统")
    var system: SassEnum? = null,

    @Cn("反馈枚举")
    var type: FeedBackEnum? = null,
    @Cn("反馈内容")
    var content: String = "",

    @Cn("关联用户信息")
    var user: IdName = IdName(),
) : BaseMarkEntity()

//----------------


@Cn("企业角色 v2废弃")
@Document
@DbEntityGroup("corp")
data class CorpRole(
        @Cn("角色名称")
    var name: String = "",

        @Cn("运维")
    var devOps: MutableList<nancal.mp.db.mongo.entity.SaasMenusDevops>,
        var forMake: MutableList<nancal.mp.db.mongo.entity.SaasMenusMake>,
        var forDevelopment: MutableList<nancal.mp.db.mongo.entity.SaasMenusDevelopment>,
        var forData: MutableList<nancal.mp.db.mongo.entity.SaasMenusData>,
        var forManagement: MutableList<nancal.mp.db.mongo.entity.SaasMenusManagement>,


        @Cn("公司")
    var corp: IdName = IdName()

) : BaseMarkEntity()


@Cn("devops 角色 v2废弃")
@Document
@DbEntityGroup("corp")
data class DevopsRole(
    var name: String = "",
    var devopsFeatures: MutableList<SubSystemEnum> = mutableListOf(),
    var corp: IdName = IdName()
) : BaseMarkEntity()

//每个角色的数据
@Cn("devops V2 角色 控制首页选项卡")
@Document
@DbEntityGroup("corp")
data class Dev2Role(
    var name: String = "",
    var remark: String = "",    //备注信息
    var devopsFeatures: MutableList<IdName> = mutableListOf(),  //首页的信息  存入的是id
    var corp: IdName = IdName()
) : BaseMarkEntity()


@Cn("项目 v2废弃")
@Document
@DbEntityGroup("corp")
data class CorpProject(
        @Cn("项目名称")
    var name: String = "",

        @Cn("开始时间")
    var startAt: LocalDate? = null,

        @Cn("结束时间")
    var endAt: LocalDate? = null,

        @Cn("描述")
    var remark: String = "",

        var users: MutableList<nancal.mp.db.mongo.entity.UserProjectDefine> = mutableListOf(),

        @Cn("公司")
    var corp: IdName = IdName()

) : BaseMarkEntity()


//    o– organization（组织-公司）
//    ou – organization unit（组织单元-部门）
//    c - countryName（国家）
//    dc - domainComponent（域名）
//    sn – suer name（真实名称）
//    cn - common name（常用名称)
@Cn("LDAP用户")
@Document
@DbEntityGroup("corp")
data class LDAPUser(

    //posixAccount 必要的参数

    @Cn("用户姓名")
    var name: String = "",

    @Cn("真实姓名")
    var realname: String = "",

    @Cn("密码")
    var userpassword: String = "",

    @Cn("身份证号")
    var uidnumber: String = "",

    @Cn("gidnumber")
    var gidnumber: String = "",

    @Cn("uid")
    var uid: String = "",

    @Cn("objectclass")
    var objectclass: String = "",

    //可选参数

    @Cn("手机号")
    var mobile: String = "",

    @Cn("邮件")
    var email: String = "",

    ) : BaseMarkEntity()

